package com.ggh.jinjilive.ui.mall.task;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.LogUtils;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityAddTaskBinding;
import com.ggh.jinjilive.dialog.SelectGoodsDialog;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.ggh.jinjilive.utils.GeneralUtils;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 添加任务
 */
@Route(path = ARouterUtils.AddTaskActivity)
public class AddTaskActivity extends BaseActivity<ActivityAddTaskBinding> {
    //适配器
    private ArrayAdapter adapter = null;
    // 数据源
    private List<String> stringList = new ArrayList<>();
    //选择商品
    private SelectGoodsDialog selectGoodsDialog;

    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).init();
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_add_task;

    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("创建任务",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);
        //数据
        stringList.clear();
        stringList.add("百分比(%)");
        stringList.add("单个金额(￥)");
        //选择商品
        selectGoodsDialog = new SelectGoodsDialog(mContext);
    }

    @Override
    public void initData() {
        super.initData();
        //适配器
        adapter = new ArrayAdapter(this, R.layout.item_text, stringList);
        binding.benefitType.setAdapter(adapter);

    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        //选择商品
        binding.imgPortrait.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null != selectGoodsDialog && !selectGoodsDialog.isShowing()){
                    selectGoodsDialog.show();
                }
            }
        });
        //主播分润
        binding.benefitType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
                String cityName = (String) adapter.getItem(position);
                if(cityName.contains("百分比")){
                    binding.etShareBenefit.setHint("分润百分比");
                }else if(cityName.contains("单个金额")){
                    binding.etShareBenefit.setHint("分润金额");
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }
}
